package com.atguigu.gulimall.ssoclient.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName HelloController
 * @Description TODO
 * @Author Administrator
 * @Date 2022/7/3 22:29
 * @Version 1.0
 **/
@Controller
public class HelloController {

    @Value(value = "${sso.server.url}")
    String ssoServerUrl;

    @ResponseBody
    @GetMapping("hello")
    public String hello(){
        return "hello";
    }



    @GetMapping("/employees")
    public String employees(Model model, HttpSession session,@RequestParam(value = "token",required = false) String token){
        Object loginUser = session.getAttribute("loginUser");
        if (!StringUtils.isEmpty(token)){
            session.setAttribute("loginUser","zhangsan");
        }
        if (loginUser==null){
            return "redirect:"+ssoServerUrl+"?redirect_url=http://client1.com:8081/employees";
        }else {

        }
        List<String> emps = new ArrayList<>();
        emps.add("张三");
        emps.add("李四");
        model.addAttribute("emps",emps);
        return "list";
    }

}
